<?php

namespace app\service;


use TCPDF;

class PdfService
{

    /**
     * 下载内容为pdf
     * @param $novel_title
     * @param $string
     * @return bool
     */
    public function downloadPdf($novel_title,$string)
    {
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true,'UTF-8', false);
        $pdf->setCreator(PDF_CREATOR);
        $pdf->setAuthor('Nicola Asuni');
        $pdf->setTitle('TCPDF Example 002');
        $pdf->setSubject('TCPDF Tutorial');
        $pdf->setKeywords('TCPDF, PDF, example, test, guide');
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        $pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        // droidsansfallback 中文字符 需额外引用放至vendor/tecnickcom/tcpdf/fonts http://pan.baidu.com/share/link?shareid=327612&uk=606208636
        $pdf->setFont('droidsansfallback', '', 16);
        $pdf->AddPage();
        $txt = <<<EOD
        $string
EOD;
        $pdf->writeHTMLCell(0, 0, '', '', $txt, 0, 1, 0, true, '', true);

//        $pdf->Image($signUrl, '', '', 35, 20, '', '', 'B', false, 300, 'R', false, false, 1, false, false, false);
        $pdf->writeHTMLCell(0, 0, '', '', date('Y年m月d日'), 0, 1, 0, true, 'R', true);

        //ob_clean(); // 可不加
        $pdf->Output(public_path().'/novel/'.$novel_title.'.pdf', 'F');
        return true;
    }
}
